﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using BrewXML.Core.Services.NavigationServices;
using Microsoft.Phone.Controls;

namespace BrewXML.WindowsPhone.Services.NavigationServices
{
   public class NavigationService : INavigationService
    {
        #region Can Go Back
        /// <summary>
        /// Gets to determine whether navigation service can go back at current page.
        /// </summary>
        public bool CanGoBack
        {
            get
            {
                var frame = Application.Current.RootVisual as PhoneApplicationFrame;
                return frame.CanGoBack;
            }
        }
        #endregion

        #region On Navigate To
        public void NavigateTo(string pageId)
        {
            var pageUri = PageNames.Instance[pageId];
            var frame = Application.Current.RootVisual as PhoneApplicationFrame;
            frame.Navigate(new Uri(pageUri, UriKind.Relative));
        }
        #endregion

        #region Go Back
        /// <summary>
        /// Navigates to previous page.
        /// </summary>
        public void GoBack()
        {
            var frame = Application.Current.RootVisual as PhoneApplicationFrame;
            frame.GoBack();
        }
        #endregion
    }
}
